generating function to closed form